import axios from 'axios'
import { MessageBox, Message } from 'element-ui'
import store from '@/store'
import { getToken } from '@/utils/auth'
import $baseUrl from '@/utils/baseURL'
const service = axios.create({
  baseURL: $baseUrl.webBaseUrl,
  timeout: 50000
})

service.interceptors.request.use(
  config => {
    if (store.getters.token) {
      config.headers['accesstoken'] = getToken();
      config.headers['organizationList'] = sessionStorage.organizationList;
      config.headers['organizationno'] = sessionStorage.organizationNo;
      config.headers['databasename'] = sessionStorage.databaseName;
      config.headers['systemTenantMark'] = sessionStorage.systemTenantMark;
      config.headers['virtualSystemNo'] = sessionStorage.virtualSystemNo||'NYXT';
      
    }
    return config
  },
  error => {
    console.log(error)
    return Promise.reject(error)
  }
)

service.interceptors.response.use(
  response => {
    return  response
  },
  error => {
    console.log('err' + error)
    Message({
      message: error.message,
      type: 'error',
      duration: 5 * 1000
    })
    return Promise.reject(error)
  }
)

export default service
